﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Book
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        /// <summary>
        /// 注册
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btn_ZC_Click(object sender, EventArgs e)
        {
            Reg reg = new Reg();
            reg.Show();
            this.Hide();
        }
        /// <summary>
        /// 登录
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btn_Login_Click(object sender, EventArgs e)
        {
            var userName = txt_UserName.Text;
            var pwd = txt_Pwd.Text;
            
            var nullUserName = string.IsNullOrEmpty(userName);
            var nullPwd = string.IsNullOrEmpty(pwd);

            var sql = string.Format("select * from Users where Username='{0}' and Password='{1}'", userName, pwd);
            var res = DbHelper.GetSelect(sql);

            if (res.Rows.Count==1)
            {
                MessageBox.Show("登录成功！", "消息提示");
                BookInfo book = new BookInfo();
                book.Show();
                this.Hide();
            }
            else if (nullUserName && nullPwd)
            {
                MessageBox.Show("用户名和密码不能为空！", "警告");
            }
            else if (nullUserName)
            {
                MessageBox.Show("用户名不能为空！", "警告");
            }
            else if (nullPwd)
            {
                MessageBox.Show("密码不能为空！", "警告");
            }
            else
            {
                MessageBox.Show("用户名和密码不存在！", "错误提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
    }
}
